import axios from 'axios'

const instance = axios.create({
  baseURL: 'https://c.y.qq.com',
  timeout: 10000, // 设置超时时间
  headers: {
    // 定义 post 请求编码格式
    // referer: 'https://c.y.qq.com/',
    // host: 'c.y.qq.com',
    post: {
      'Content-Type': 'application/x-www-form-urlencoded;charset=UTF-8'
    }
  }
})
export default {
  post(url, data = {}) {
    return new Promise((resolve, reject) => {
      instance.post(url, data).then(
        response => {
          resolve(response.data)
        },
        err => {
          reject(err)
        }
      )
    })
  },
  get(url, params = {}) {
    return new Promise((resolve, reject) => {
      instance
        .get(url, {
          params: params
        })
        .then(response => {
          resolve(response.data)
        })
        .catch(err => {
          reject(err)
        })
    })
  }
}
